package com.zyl.basis.state;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zhaoyl
 * @date 2024/5/27 15:38
 * @description 说明
 *sleep指定当前线程阻塞毫秒数，不会释放锁。到时间后线程进入就绪状态
 */
public class TestSleep {
    //模拟倒计时
    public static void tenDown() throws InterruptedException {
        int num =10;
        while (true){
            Thread.sleep(1000);//1秒
            System.out.println(num--);
            if (num<=0){
                break;
            }
        }
    }

    public static void main(String[] args) {
        Date start = new Date(System.currentTimeMillis());//获取系统当前时间

        try {
            System.out.println(new SimpleDateFormat("HH:mm:ss").format(start));
            tenDown();
            start = new Date(System.currentTimeMillis());//获取系统当前时间
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
